//
//  ByShopIndexPartVC.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/1.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByShopIndexPartVC.h"

// cell
#import "ByCellShopProduct.h"               // 商品cell

// view
#import "ByViewShopProductSort.h"           // 排序

@interface ByShopIndexPartVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView   *table;
@property (nonatomic, strong) UIImageView   *header;

@end

@implementation ByShopIndexPartVC
{
    NSInteger _items;
}

#pragma mark - view method
- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.title = @"专区";
    [self addLeftBackBarButtonItem];
    
    [self createTableView];
}

#pragma mark - 创建视图
- (void)createTableView {
    
    self.table = [[UITableView alloc] init];
    self.table.backgroundColor = BY_BG_COLOR;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0)).priorityMedium();
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(0);
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
        }
    }];
    
    // 注册
    [self.table registerClass:[ByCellShopProduct class] forCellReuseIdentifier:@"productCell"];
    
    // 头视图
    _header = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
    _header.image = [UIImage imageNamed:@"头视图背景"];
    self.table.tableHeaderView = _header;
    
}


#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ByCellShopProduct *cell = [tableView dequeueReusableCellWithIdentifier:@"productCell"];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return (SCREEN_WIDTH - 20) / 2 + 40 + 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 0) {
        return 40 + 10;
    }
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        UIView *header = [UIView new];
        
        ByViewShopProductSort *sortView = [ByViewShopProductSort new];
        [header addSubview:sortView];
        
        UIView *marginView = [UIView new];
        [header addSubview:marginView];
        
        [sortView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(header).insets(UIEdgeInsetsMake(0, 0, 10, 0));
        }];
        
        return header;
    }
    return UIView.new;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return UIView.new;
}


@end
